﻿using de.wolfmarco.pas.Client.Modules;
using Microsoft.Practices.Prism.Modularity;
using System;
using System.Collections.Generic;
using System.IO;

namespace de.wolfmarco.pas.Client
{
    public class DynamicDirectoryModuleCatalog : DirectoryModuleCatalog
    {
        public DynamicDirectoryModuleCatalog()
        {
            AddModule(typeof(StartMenuModule));

            string modulePath = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Modules");

            if (!Directory.Exists(modulePath))
                Directory.CreateDirectory(modulePath);

            ModulePath = modulePath;
        }

        protected override void InnerLoad()
        {
            base.InnerLoad();

            string[] folders = Directory.GetDirectories(ModulePath, "*", SearchOption.AllDirectories);

            foreach (string folder in folders)
            {
                ModulePath = folder;
                base.InnerLoad();
            }
        }
    }
}
